﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Mvc;
using System.Web.Routing;

namespace IInject.Web.Mvc
{
    public class IInjectControllerActivator : IControllerActivator
    {
		private IContainer _container;

		public IInjectControllerActivator(IContainer container)
		{
			if (container == null)
			{
				throw new ArgumentNullException("container");
			}

			_container = container;
		}

		IController IControllerActivator.Create(RequestContext requestContext, Type controllerType)
		{
			try
			{
				return _container.Get(controllerType) as IController;
			}
			catch (Exception)
			{
				return null;
			}
		}
	}
}
